package com.kfm.jdbc.day01;

import java.sql.SQLException;

public class Transfer {

    public static void main(String[] args) {
            transfer("老兵", "新兵", 10);
    }


    public static void transfer(String from, String to, double money){
        // 简化操作 直接做转账操作
        String url = "jdbc:mysql://localhost:3306/company_info";
        String user = "root";
        String pass = "root";

        DBHelper dbHelper = new DBHelper(url, user, pass);

        // 根据姓名修改 余额
        String sql = "update customer set balance = balance - ? where customerName = ?";

        try {
            // 扣钱
            int update = dbHelper.update(sql, money, from);
            int a = 1 / 0; // 模拟错误
            // 加钱
//            sql = "update customer set balance = balance + ? where customerName = ?";
            dbHelper.update(sql, -money, to);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }
}
